<template>
	<view class="content">
		<view v-if="countDown > 0" class="time-box">
			<view class="time-circle">
				{{countDown}}
			</view>
		</view>
		<view v-else class="icon-box">
			<image class="icon" :src="icon" mode=""></image>
		</view>
		<view v-if="title" class="title">
			{{title}}
		</view>
		<view v-if="desc" class="desc">
			{{desc}}
		</view>
		<template v-if="link">
			<view class="btn" @click="back">返回修改信息</view>
			<view class="btn-tip" @click="toCustomerService">联系客服</view>
		</template>
	</view>
</template>

<script>
	import { toCustomerService } from '@/utils/index.js'
	export default {
		name: 'check-status',
		props: {
			status: {
				type: Number,
				default: -1,
			},
			icon: {
				type: String,
				default: ''
			},
			title: {
				type: String,
				default: ''
			},
			desc: {
				type: String,
				default: ''
			},
			link: {
				type: String,
				default: ''
			},
			time: {
				type: Number,
				default: 0, // 单位秒
			}
		},
		data() {
			return {
				countDown: 0
			}
		},
		watch: {
			time: {
				handler(newVal, oldName) {
					this.countDown = newVal;
					let progress = 0;
					if (this.countDown > 0) {
						progress = setInterval(() => {
							this.countDown --;
							if (this.countDown === 0) {
								clearInterval(progress)
							}
						}, 1000)
					} else {
						if (progress > 0) {
							clearInterval(progress)
						}
					}
				},
				immediate: true,
			}
		},
		methods: {
			back() {
				if (this.link) {
					uni.redirectTo({
						url: this.link
					})
				}
			},
			toCustomerService() {
				toCustomerService();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.flex {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.flex-center {
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.content {
		width: 100%;
		background-color: #F8FAFD;
		position: relative;
		.time-box {
			width: 180rpx;
			height: 180rpx;
			border-radius: 50%;
			margin: 0 auto 30rpx auto;
			.time-circle {
				width: 150rpx;
				height: 150rpx;
				border: 15rpx solid #F7D35D;
				border-radius: 50%;
				color: #3D3D3D;
				font-size: 32rpx;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}
		.icon-box {
			display: flex;
			justify-content: center;
			align-items: center;
			margin-bottom: 40rpx;
			.icon {
				width: 174rpx;
				height: 174rpx;
			}
		}
		.title {
			color: #3D3D3D;
			font-size: 32rpx;
			font-weight: bold;
			height: 50rpx;
			line-height: 50rpx;
			text-align: center;
			margin-bottom: 6rpx;
		}
		.desc {
			color: #7E7D7D;
			font-size: 26rpx;
			line-height: 40rpx;
			text-align: center;
		}
		.btn {
			width: 100%;
			height: 72rpx;
			line-height: 72rpx;
			border-radius: 60rpx;
			font-size: 28rpx;
			text-align: center;
			color: #3D3D3D;
			margin-top: 50rpx;
			background: linear-gradient(97deg, #FADF5D 19%, #F7D35D 80%);
		}
		.btn-tip {
			width: 100%;
			text-align: center;
			margin-top: 24rpx;
			color: #7E7D7D;
			font-size: 28rpx;
			line-height: 44rpx;
		}
	}
</style>